package com.kiki.stater;

import java.util.concurrent.TimeUnit;

/**
 * Created by mazeyi on 2020/10/30.
 */
public class ThreadLocalTest {
    static ThreadLocal threadLocal = new ThreadLocal();

    public static void main(String[] args) {

        Thread t1 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(threadLocal.get());
        });


        Thread t2 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            threadLocal.set(111);
        });

        t1.start();
        t2.start();
    }
}